<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    async function main() {
      //1. 普通值
      // let result = await 2;
      //2. 成功的 promise 对象
      // let result = await new Promise((resolve, reject) => {
      //   resolve('OKOK');
      // });
      //3. 失败的 promise 对象
      // try {
      //   let value = await new Promise((resolve, reject) => {
      //     reject('Error');
      //   });
      //   //这里相当于是 promise then 指定的成功回调
      //   console.log(value);
      // } catch (reason) {
      //   //这里相当于是 promise then 指定的失败回调
      //   console.log(reason);
      // }
      //4. 异步任务的 promise    wait 等待
      let p = new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve('Yes');
        }, 2000);
      });
      console.log(p);
      let result = await p;
      console.log(result, p);
    }
    main();

  </script>
</body>

</html>